import { queryTagList } from "@/api/tag.api";
import { Tag } from "@/types/tag";
import { useCallback, useEffect, useState } from "react";

interface TagData {
  list: Array<Tag>;
  current: Tag | null;
}
export const useTagList = (): {
  tagList: TagData;
  setTagList:(tagData:TagData)=>void
} => {
  const [tagList ,setTagList]= useState<TagData>({
    list: [],
    current: null,
  });
  const getTagList = useCallback( async () => {
    const res = await queryTagList();
    if (res.code === 200) {
      setTagList({
        ...tagList,
        list:res.data||[]
      })
    }
  },[tagList]) 
  useEffect(()=>{
    getTagList();
  // eslint-disable-next-line react-hooks/exhaustive-deps
  },[])
 
  return {
    tagList,
    setTagList
  };
};
